﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NextCMS.Models;
using System.Collections.ObjectModel;

/// <summary>
/// Summary description for ApplicationCache
/// </summary>
public class ApplicationCache
{
	public ApplicationCache()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public static Collection<SiteLanguageModel> SiteLanguages
    {
        get
        {
            Collection<SiteLanguageModel> _SiteLanguages = new Collection<SiteLanguageModel>();
            if (HttpContext.Current.Application["SiteLanguages"] == null)
            {
                using (SiteLanguagesHelper helper = new SiteLanguagesHelper())
                {
                    foreach (SiteLanguageModel sm in helper.GetAll().ToList())
                    {
                        _SiteLanguages.Add(sm);
                    }
                }
                HttpContext.Current.Application["SiteLanguages"] = _SiteLanguages;
            }

            return HttpContext.Current.Application["SiteLanguages"] as Collection<SiteLanguageModel>;
        }
        set { HttpContext.Current.Application["SiteLanguages"] = value; }
    }
    public static Collection<SiteModel> Sites
    {
        get
        {
            Collection<SiteModel> _Sites = new Collection<SiteModel>();
            if (HttpContext.Current.Application["Sites"] == null)
            {
                using (SitesHelper helper = new SitesHelper())
                {
                    foreach (SiteModel sm in helper.GetAll().ToList())
                    {
                        _Sites.Add(sm);
                    }
                }
                HttpContext.Current.Application["Sites"] = _Sites;
            }

            return HttpContext.Current.Application["Sites"] as Collection<SiteModel>;
        }
        set { HttpContext.Current.Application["Sites"] = value; }
    }
    public static Collection<SiteSettingsModel> SiteSettings
    {
        get
        {
            Collection<SiteSettingsModel> _SiteSettings = new Collection<SiteSettingsModel>();
            if (HttpContext.Current.Application["SiteSettings"] == null)
            {
                using (SiteSettingsHelper helper = new SiteSettingsHelper())
                {
                    foreach (SiteSettingsModel sm in helper.GetAll().ToList())
                    {
                        _SiteSettings.Add(sm);
                    }
                }
                HttpContext.Current.Application["SiteSettings"] = _SiteSettings;
            }

            return HttpContext.Current.Application["SiteSettings"] as Collection<SiteSettingsModel>;
        }
        set { HttpContext.Current.Application["SiteSettings"] = value; }
    }
}